home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / cagd_lib / cagdpoly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  4.1 KB  |  101 lines

  1. /******************************************************************************
  2. * CagdPoly.c - Generic Curve/Surface to polygon/polylines conversion routines.*
  3. *******************************************************************************
  4. * Written by Gershon Elber, July. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * Routine to convert a single surface to set of triangles             *
  11. * approximating it. FineNess is a finess control on result and the bigger it *
  12. * is more triangles may result. a value of 10 is a good start value.         *
  13. * NULL is returned in case of an error, otherwise list of CagdPolygonStruct. *
  14. *****************************************************************************/
  15. CagdPolygonStruct *CagdSrf2Polygons(CagdSrfStruct *Srf, int FineNess,
  16.     CagdBType ComputeNormals, CagdBType FourPerFlat, CagdBType ComputeUV)
  17. {
  18.     switch (Srf -> GType) {
  19.     case CAGD_SBEZIER_TYPE:
  20.         return BzrSrf2Polygons(Srf, FineNess, ComputeNormals, FourPerFlat,
  21.                                    ComputeUV);
  22.     case CAGD_SBSPLINE_TYPE:
  23.         return BspSrf2Polygons(Srf, FineNess, ComputeNormals, FourPerFlat,
  24.                                    ComputeUV);
  25.     case CAGD_SPOWER_TYPE:
  26.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  27.         return NULL;
  28.     default:
  29.         FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  30.         return NULL;
  31.     }
  32. }
  33.  
  34. /*****************************************************************************
  35. * Routine to convert a single surface to NumOfIsolines polylines list         *
  36. * in each param. direction with SamplesPerCurve in each isoparametric curve. *
  37. * Polyline are always E3 of CagdPolylineStruct type.                 *
  38. * Iso parametric curves are sampled equally spaced in parametric space.         *
  39. * NULL is returned in case of an error, otherwise list of CagdPolylineStruct.*
  40. *****************************************************************************/
  41. CagdPolylineStruct *CagdSrf2Polylines(CagdSrfStruct *Srf, int NumOfIsocurves[2],
  42.                               int SamplesPerCurve)
  43. {
  44.     switch (Srf -> GType) {
  45.     case CAGD_SBEZIER_TYPE:
  46.         return BzrSrf2Polylines(Srf, NumOfIsocurves, SamplesPerCurve);
  47.     case CAGD_SBSPLINE_TYPE:
  48.         return BspSrf2Polylines(Srf, NumOfIsocurves, SamplesPerCurve);
  49.     case CAGD_SPOWER_TYPE:
  50.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  51.         return NULL;
  52.     default:
  53.         FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  54.         return NULL;
  55.     }
  56. }
  57.  
  58. /*****************************************************************************
  59. * Routine to convert a single surface to NumOfIsoline isocurves in each      *
  60. * param. direction.                                 *
  61. *   Iso parametric curves are sampled equally spaced in parametric space.    *
  62. * NULL is returned in case of an error, otherwise list of CagdPolylineStruct.*
  63. *****************************************************************************/
  64. CagdCrvStruct *CagdSrf2Curves(CagdSrfStruct *Srf, int NumOfIsocurves[2])
  65. {
  66.     switch (Srf -> GType) {
  67.     case CAGD_SBEZIER_TYPE:
  68.         return BzrSrf2Curves(Srf, NumOfIsocurves);
  69.     case CAGD_SBSPLINE_TYPE:
  70.         return BspSrf2Curves(Srf, NumOfIsocurves);
  71.     case CAGD_SPOWER_TYPE:
  72.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  73.         return NULL;
  74.     default:
  75.         FATAL_ERROR(CAGD_ERR_UNDEF_SRF);
  76.         return NULL;
  77.     }
  78. }
  79.  
  80. /*****************************************************************************
  81. * Routine to convert a single curve to polyline with SamplesPerCurve         *
  82. * samples. Polyline is always E3 of CagdPolylineStruct type.             *
  83. * Curve is sampled equally spaced in parametric space.                 *
  84. * NULL is returned in case of an error, otherwise CagdPolylineStruct.         *
  85. *****************************************************************************/
  86. CagdPolylineStruct *CagdCrv2Polyline(CagdCrvStruct *Crv, int SamplesPerCurve)
  87. {
  88.     switch (Crv -> GType) {
  89.     case CAGD_CBEZIER_TYPE:
  90.         return BzrCrv2Polyline(Crv, SamplesPerCurve);
  91.     case CAGD_CBSPLINE_TYPE:
  92.         return BspCrv2Polyline(Crv, SamplesPerCurve, NULL);
  93.     case CAGD_CPOWER_TYPE:
  94.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  95.         return NULL;
  96.     default:
  97.         FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  98.         return NULL;
  99.     }
  100. }
  101.